#!/bin/bash

. $(dirname $0)/functions

BASE=$BASEDIR/
BUILD=$BUILDDIR/

if [ -n "$MSYSTEM" ]; then
    # Avoid Windows drive letter issues in the path of DEF:vname=rrdfile under MSYS or MSYS2
    RRD=rpn1.rrd
else
    RRD=${BUILD}rpn1.rrd
fi

$RRDTOOL create $RRD --start 920804400 DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:1:24 RRA:AVERAGE:0.5:6:10
report "create"
$RRDTOOL update $RRD 920804700:12345 920805000:12357 920805300:12363
$RRDTOOL update $RRD 920805600:12363 920805900:12363 920806200:12373
$RRDTOOL update $RRD 920806500:12383 920806800:12393 920807100:12399
$RRDTOOL update $RRD 920807400:12405 920807700:12411 920808000:12415
$RRDTOOL update $RRD 920808300:12420 920808600:12422 920808900:12423
report "update"
# blank out any absolute coordinates, as they might differ
$BLANK < $BASEDIR/rpn1.output > $BASEDIR/rpn1.output.out
$RRDTOOL graphv $BASEDIR/rpn1.out \
      --start 920804400 --end 920808000               \
      DEF:my-speed=$RRD:speed:AVERAGE              \
      CDEF:nonans01=my-speed,UN,0,my-speed,IF             \
      CDEF:kmh=nonans01,3600,*                          \
      CDEF:fast123456789012345678901234567890=kmh,100,GT,100,0,IF                   \
      CDEF:over=kmh,100.000000000000000000000000000000000000,GT,kmh,100,-,0,IF             \
      CDEF:good=kmh,100,GT,0,kmh,IF                   \
      VDEF:f=fast123456789012345678901234567890,AVERAGE \
      VDEF:g=good,MAXIMUM \
      VDEF:o=over,MINIMUM \
      VRULE:920806500:"foo" \
      PRINT:f:'%lf' \
      PRINT:g:'%lf' \
      PRINT:o:'%lf' | $BLANK | $DIFF9 - $BASEDIR/rpn1.output.out
report "graphv"
